from PySide2 import QtGui,QtWidgets
from ui.chatItemWidget_ui import Ui_widget
from ui import msgItemOtherWidget_ui,msgItemSelfWidget_ui,msgItemTimeWidget_ui

class ChatItemFrame(QtWidgets.QFrame):
    def __init__(self, name):
        super().__init__()
        self.ui = Ui_widget()
        self.ui.setupUi(self)
        self.ui.name.setText(name)


class MsgItemOtherWidget(QtWidgets.QFrame):
    def __init__(self, text=' '):
        super().__init__()
        self.setStyleSheet("")
        self.ui = msgItemOtherWidget_ui.Ui_Frame()
        self.ui.setupUi(self)
        self.ui.textBrowser.setReadOnly(False)
        self.ui.textBrowser.document().contentsChanged.connect(self.textAreaChanged)
        self.ui.textBrowser.append(text)

    def textAreaChanged(self):
        document = self.ui.textBrowser.document()
        margins = self.ui.textBrowser.contentsMargins()
        height = document.size().height() + margins.top() + margins.bottom()
        self.ui.textBrowser.setFixedHeight(height)

    def resizeEvent(self, event):
        super().resizeEvent(event)
        self.textAreaChanged()

class MsgTextBrowserWidget(QtWidgets.QTextBrowser):
    def resizeEvent(self, event):
        super().resizeEvent(event)
        self.textAreaChanged()

    # def wheelEvent(self, event):
    #     # Do nothing to disable the scroll wheel
    #     pass

